#pragma once
#include <iostream>
#include <cmath>
#include <vector>
#include <utility>
#include <sstream>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

using namespace std;
class Half_thinning_Algorithm
{
public:
	Half_thinning_Algorithm(void);
	void run(IplImage *source);
	void run_half_thinning(IplImage *source);
	int calculate_estimated_stroke_width(IplImage *source);
	double calculate_dc(int x, int y, IplImage *source);
	virtual ~Half_thinning_Algorithm(void);

private:

	vector< pair<int,int> > borders;
	static int N[3][3];
	static int A0[48];

	int *runlength_hash_table;


	bool check_first_condition(int** mask);
	int check_second_condition(int** mask);
	bool check_third_condition(int** mask);
	bool check_fourth_condition(int** mask);
	bool check_fifth_condition(int** mask);
	bool check_sixth_condition(int** mask);
	bool check_seventh_condition(int** mask);
	bool check_eighth_condition(int** mask);
	bool check_border_condition(int** mask);

	void scan_horizontal(IplImage *source);
	void scan_vertical(IplImage *source);
	void marking_borders(IplImage *source);
	void remove_spurious_loops(IplImage *source);
};

